package com.vay.de.dang.online;

import android.os.Bundle;
import android.text.TextUtils;

import com.vay.de.dang.online.databinding.AcSplashBinding;
import com.vay.de.dang.online.util.CallerUtil;
import com.vay.de.dang.online.util.VnContext;
import com.vay.de.dang.online.util.VnUIManager;
import com.vay.de.dang.online.util.VnDefine;
import com.vay.de.dang.online.util.VnHandler;
import com.vay.de.dang.online.ui.BaseActivity;
import com.vay.de.dang.online.ui.HomeActivity;
import com.vay.de.dang.online.web.BaseApi;

public class SplashActivity extends BaseActivity {

    private AcSplashBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = AcSplashBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        binding.tvVersion.setText("v" + VnContext.versionName);

        VnHandler.runUIDelayed(() -> {
            if (!mPf.readBoolean(VnDefine.ReadKeyPermission)) {
                VnUIManager.nextActivity(mActivity, ReqPerActivity.class, true);
            } else {
                VnUIManager.nextActivity(mActivity, HomeActivity.class, true);
            }
        }, 2000);

        // 运营商错误次数
        String curDay = CallerUtil.currentTime();
        String day = mPf.readString("_vn_day");
        if (TextUtils.isEmpty(day) || !day.equals(curDay)) {
            mPf.putString("_vn_day", curDay);
            mPf.putInt("_vn_error_count", 0);
        }

        // 埋点
        BaseApi.execBuriedPoint(1000, 1000, "启动", "启动");
    }

    @Override
    public void onBackPressed() {

    }
}
